import okx.PublicData as PublicData
from datetime import datetime
import time
import okx.MarketData as MarketData
from utils.log import Loggers
from utils.config import *
from utils.utils import *
import numpy as np

flag = "0"  # 实盘:0 , 模拟盘：1

publicDataAPI = PublicData.PublicAPI(flag=flag,domain=server_url)

for i in config_down_instId:
    instId = f'{i}-USDT-SWAP'
    # 获取永续合约历史资金费率
    result = publicDataAPI.funding_rate_history(
        instId=instId,
    )
    realizedRateArr = []
    number = 0
    for item in result['data']:
        realizedRateArr.append(round(float(item['realizedRate'])*100,4)) 
        number+=1

    arr_np = np.array(realizedRateArr)
    print(f"{instId} 平均值：{round(np.mean(arr_np),4)}% 中位数：{round(np.median(arr_np),4)}%  累计：{round(np.sum(arr_np),4)}%")
    time.sleep(1)